﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using W_Fish.Models;

namespace W_Fish.Controllers
{
    public class LoginController : Controller
    {
        //
        // GET: /Login/
        FishManagement_Timkiemx db = new FishManagement_Timkiemx();
        public ActionResult Login()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Login(FormCollection collection)
        {
            string txtname = collection["username"];
            string txtpass = collection["pass"];

            var find = (from per in db.Posters where txtname == per.name && txtpass == per.pass select per).ToList<Poster>();
            
            if (find.Count == 0)
            {
                ViewBag.meg = "Mật khẩu chưa đúng hoặc tài khoản không tồn tại!";
                return View();
            }
            else
            {
                if (find.First<Poster>().admin == true)
                {
                    return RedirectToAction("MainAdmin", "Admin", new { user = txtname });
                }
                else return RedirectToAction("MainPoster", "PosterView", new { user = txtname });

            }
        }


        public ActionResult ChangePass()
        {
            
            return View();
        }


        public ActionResult LostPass()
        {
            return View();
        }
    }
}
